﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;

namespace Demo.Extensions
{
    public static class ControlExtensions
    {
        public static void SafeExecute(this Control This, Action action)
        {
            try
            {
                action();
            }
            catch (ApplicationException ex)
            {
                ScriptManager.RegisterStartupScript(This, This.GetType(), "error", string.Format("<script type=\"text/javascript\">alert('{0}');</script>", ex.Message), false);
            }
            catch (Exception ex)
            {
                ScriptManager.RegisterStartupScript(This, This.GetType(), "error", string.Format("<script type=\"text/javascript\">alert('{0}');</script>", ex.Message), false);
            }
        }
    }
}